﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LeadTeam.Exam.Entities;
using System.Net;
using LeadTeam.Exam.Utility;

namespace LeadTeam.Exam.AdminTool
{
    public class OrganizationsControllor
    {
        //define view and model      
        public OrganizationsView view;
        public IList<Organizations> model;

        public OrganizationsControllor(OrganizationsView view)
        {
            //get model
            model = GetModelData();
            //set view
            this.view = view;
            //set controller for the view
            this.view.Controllor = this;
        }

        /// <summary>
        /// Make the controller to get model and refresh the view
        /// </summary>
        public void UpdateModel()
        {
            model = GetModelData();
            view.UpdateModel();
        }

        /// <summary>
        /// Get the model data from the remote data service
        /// </summary>
        /// <returns></returns>
        private IList<Organizations> GetModelData()
        {
            ReponseRes res = RequestHelper.RequestGet(ConfigHelper.GetRootServiceUrl() + "Organization");
            IList<Organizations> list = SerializeHelper.JsonDeserialize<List<Organizations>>(res.ReponseStr);
            return list;
        }
    }
}
